#include "powermeter.h"

PowerMeter::PowerMeter(QObject *parent) : QObject(parent) {
}

quint16 PowerMeter::getCurrentFWDPower() {
  return(currentFWDPower);
}

quint16 PowerMeter::getCurrentREFPower() {
  return(currentREFPower);
}

float PowerMeter::getCurrentVSWR() {
  return(currentVSWR);
}

quint8 PowerMeter::getPickupType() {
  return(pickupPowerLevel);
}

quint16 PowerMeter::getAlarmLevelFWDPower() {
  return(alarmLevelFWDPower);
}

quint16 PowerMeter::getAlarmLevelREFPower() {
  return(alarmLevelREFPower);
}

float PowerMeter::getAlarmLevelVSWR() {
  return(alarmLevelVSWR);
}

quint16 PowerMeter::getDataPollInterval() {
  return(dataPollInterval);
}

void PowerMeter::setCurrentFWDPower(quint16 value) {
  currentFWDPower = value;
}

void PowerMeter::setCurrentREFPower(quint16 value) {
  currentREFPower = value;
}

void PowerMeter::setCurrentVSWR(float value) {
  currentVSWR = value;
}

void PowerMeter::setPickupType(quint8 type) {
  pickupPowerLevel = type;
}

void PowerMeter::setAlarmLevelFWDPower(quint16 value) {
  alarmLevelFWDPower = value;
}

void PowerMeter::setAlarmLevelREFPower(quint16 value) {
  alarmLevelREFPower = value;
}

void PowerMeter::setAlarmLevelVSWR(float value) {
  alarmLevelVSWR = value;
}

void PowerMeter::setDataPollInterval(quint16 value) {
  dataPollInterval = value;
}

void PowerMeter::powerMeterEvent() {
  setCurrentFWDPower(qrand() % ((1500 + 1) - 0) + 0);
  setCurrentREFPower(currentFWDPower / 20);
  setCurrentVSWR(1.5);

  emit valueChanged();
}

void PowerMeter::getData(QJsonObject &json) {
  json["currentFWDPower"] = currentFWDPower;
  json["currentREFPower"] = currentREFPower;
  json["currentVSWR"] = currentVSWR;
  json["pickupPowerLevel"] = pickupPowerLevel;
  json["alarmLevelFWDPower"] = alarmLevelFWDPower;
  json["alarmLevelREFPower"] = alarmLevelREFPower;
  json["alarmLevelVSWR"] = alarmLevelVSWR;
  json["dataPollInterval"] = dataPollInterval;
}

void PowerMeter::putData(const QJsonObject &json) {
  currentFWDPower = json["currentFWDPower"].toDouble();
  currentREFPower = json["currentREFPower"].toDouble();
  currentVSWR = json["currentVSWR"].toDouble();
  pickupPowerLevel = json["pickupPowerLevel"].toDouble();

  alarmLevelFWDPower = json["alarmLevelFWDPower"].toDouble();
  alarmLevelREFPower = json["alarmLevelREFPower"].toDouble();
  alarmLevelVSWR = json["alarmLevelVSWR"].toDouble();
  dataPollInterval = json["dataPollInterval"].toDouble();
}
